import Toast from '@vant/weapp/toast/toast';
Component({
  properties: {
    scenicName: {
      type: String,
      value: ""
    },
    scenicDes: {
      type: String,
      value: ""
    },
    imageSrc: {
      type: String,
      value: ""
    },
    scenicPrice: {
      type: Number,
      value: 0
    },
    scenicRePrice: {
      type: Number,
      value: 0
    },
    reservationNumber: {
      type: String,
      value: ""
    },
    item: {
      type: Object,
      value: {}
    }
  },
  data: {
    delLoading: false,
    comLoading: false,
    celLoading: false
  },
  methods: {
    jumpHotelDetail(e) {
      const pageThis = this
      wx.navigateTo({
        url: `/pages/ticketDetail/index`,
        success(res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('sendOutData', {
            value: pageThis.properties
          })
        }
      });
    },
    getOrderStatus(status) {

    },
    async deleteOrder(e) {
      wx.showLoading({ title: '加载中', mask: true })
      var id = e.currentTarget.dataset.id
      const status = e.currentTarget.dataset.status
      const { result } = await wx.cloud.callFunction({ name: 'quickstartFunctions', data: { type: 'updateOrder', status: parseInt(status), _id: id }})
      if (result && result.stats && result.stats.updated === 1) {
        wx.hideLoading()
        wx.showToast({ title: '操作成功', icon: 'success' })
        this.triggerEvent('deleteItem', { status: parseInt(status), id })
      } else {
        wx.hideLoading()
        wx.showToast({ title: '操作失败', icon: 'error' })
      }
    },
    async updateOrder(e) {
      wx.showLoading({ title: '加载中', mask: true })
      const id = e.currentTarget.dataset.id
      const status = e.currentTarget.dataset.status
      const { result } = await wx.cloud.callFunction({ name: 'quickstartFunctions', data: { type: 'updateOrder', status: parseInt(status), _id: id }})
      if (result && result.stats && result.stats.updated === 1) {
        wx.hideLoading()
        wx.showToast({ title: '操作成功', icon: 'success' })
        this.triggerEvent('updateItem', { status: parseInt(status), id })
      } else {
        wx.hideLoading()
        wx.showToast({ title: '操作失败', icon: 'error' })
      }
    }
  }
})